<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;
use DB;
class NotiController extends Controller{
   //通知设置页面
    public function getIndex(Request $request){
        //获取登录id
        // $agentId = session('agentId');
        $agentId = $request->cookie('agentId');
        if($agentId == 1){
            //查询通知设置表
            $data = DB::table('sa_noti_set') -> get();
        }else{
            $data = [];
        }
        return view('admin.noti.index',['data'=>$data]);
    }
    
    // 修改通知选项
    public function getUpdate(Request $request)
    {
        $num = $request -> get('num');
        $val = $request -> get('val');
        $mk = false;
        $noti_id = '';
        $field = '';
        switch($num){
            case 0:
                $noti_id = 1;
                $field = 'noti_area';
                $mk = true;
                break;
            case 1:
                $noti_id = 1;
                $field = 'noti_building';
                $mk = true;
                break;
            case 2:
                $noti_id = 1;
                $field = 'noti_room';
                $mk = true;
                break;
            case 3:
                $noti_id = 1;
                $field = 'status';
                $mk = true;
                break;
            case 4:
                $noti_id = 2;
                $field = 'noti_area';
                $mk = true;
                break;
            case 5:
                $noti_id = 2;
                $field = 'noti_building';
                $mk = true;
                break;
            case 6:
                $noti_id = 2;
                $field = 'noti_room';
                $mk = true;
                break;
            case 7:
                $noti_id = 2;
                $field = 'status';
                $mk = true;
                break;
            case 8:
                $noti_id = 3;
                $field = 'noti_area';
                $mk = true;
                break;
            case 9:
                $noti_id = 3;
                $field = 'noti_building';
                $mk = true;
                break;
            case 10:
                $noti_id = 3;
                $field = 'noti_room';
                $mk = true;
                break;
            case 11:
                $noti_id = 3;
                $field = 'status';
                $mk = true;
                break;
            default:
        }
        if($mk){
            $rows = DB::table('sa_noti_set') -> where('id','=',$noti_id) -> update([$field =>$val]);
            if($rows)
            {
                echo '修改成功';
            }else{
                echo '修改失败'; 
            }
        }else{
            echo '错误信息';
        }
        
    }
}
